package windows;

/*
 * Christopher Deckers (chrriis@nextencia.net)
 * http://www.nextencia.net
 *
 * See the file "readme.txt" for information on usage and redistribution of
 * this file, and for a DISCLAIMER OF ALL WARRANTIES.
 */

import java.awt.BorderLayout;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.SwingUtilities;

import chrriis.common.UIUtils;
import chrriis.dj.nativeswing.swtimpl.NativeInterface;
import chrriis.dj.nativeswing.swtimpl.components.HTMLEditorListener;
import chrriis.dj.nativeswing.swtimpl.components.HTMLEditorSaveEvent;
import chrriis.dj.nativeswing.swtimpl.components.JHTMLEditor;

/**
 * @author Christopher Deckers
 */
public class SimpleHTMLEditorExample extends JPanel {

  /**
	 * 
	 */
	private static final long serialVersionUID = 1L;
protected static final String LS = System.getProperty("line.separator");

  public SimpleHTMLEditorExample() {
    super(new BorderLayout());
    String configurationScript =
        "FCKConfig.ToolbarSets[\"Default\"] = [\n" +
        "['Source','DocProps','-','Save','NewPage','Preview','-','Templates'],\n" +
        "['Cut','Copy','Paste','PasteText','PasteWord','-','Print','SpellCheck'],\n" +
        "['Undo','Redo','-','Find','Replace','-','SelectAll','RemoveFormat'],\n" +
        "['Form','Checkbox','Radio','TextField','Textarea','Select','Button','ImageButton','HiddenField'],\n" +
        "'/',\n" +
        "['Style','FontFormat','FontName','FontSize'],\n" +
        "['TextColor','BGColor'],\n" +
        "'/',\n" +
        "['Bold','Italic','Underline','StrikeThrough','-','Subscript','Superscript'],\n" +
        "['OrderedList','UnorderedList','-','Outdent','Indent','Blockquote'],\n" +
        "['JustifyLeft','JustifyCenter','JustifyRight','JustifyFull'],\n" +
        "['Link','Unlink','Anchor'],\n" +
        "['Image','Flash','Table','Rule','Smiley','SpecialChar','PageBreak', '-', 'ShowBlocks'],\n" +
        "];\n" +
        "FCKConfig.ToolbarCanCollapse = false;\n";
    final JHTMLEditor htmlEditor = new JHTMLEditor(JHTMLEditor.HTMLEditorImplementation.FCKEditor, JHTMLEditor.FCKEditorOptions.setCustomJavascriptConfiguration(configurationScript));
    htmlEditor.addHTMLEditorListener(new HTMLEditorListener() {
      public void saveHTML(HTMLEditorSaveEvent e) {
        JOptionPane.showMessageDialog(SimpleHTMLEditorExample.this, "The data of the HTML editor could be saved anywhere...");
      }
    });
    add(htmlEditor, BorderLayout.CENTER);
    htmlEditor.setHTMLContent("xxx");
  }

  /* Standard main method to try that test as a standalone application. */
  public static void main(String[] args) {
    UIUtils.setPreferredLookAndFeel();
    NativeInterface.open();
    SwingUtilities.invokeLater(new Runnable() {
      public void run() {
        JFrame frame = new JFrame("DJ Native Swing Test");
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.getContentPane().add(new SimpleHTMLEditorExample(), BorderLayout.CENTER);
        frame.setSize(800, 600);
        frame.setLocationByPlatform(true);
        frame.setVisible(true);
      }
    });
    NativeInterface.runEventPump();
  }

}

